﻿Imports SIGI.Common.BE
Imports System.Data.SqlClient
Imports System.Configuration

Public Class SexDAC

#Region "<< -Search- >>"
    Public Shared Function Search() As List(Of SexBE)
        Dim wSqlConn As SqlConnection = Nothing
        Dim wSqlCmd As SqlCommand = Nothing
        Dim wReader As SqlDataReader = Nothing
        Dim wConnStr As String = String.Empty

        Dim wSexList As List(Of SexBE) = Nothing
        Dim wSexBE As SexBE = Nothing

        Try
            'Obtengo la cadena de conexión
            wConnStr = ConfigurationManager.ConnectionStrings("connString").ConnectionString
            'Creo la conexión a la BD
            wSqlConn = New SqlConnection(wConnStr)
            'Creo el comando
            wSqlCmd = New SqlCommand()
            wSqlCmd.Connection = wSqlConn
            wSqlCmd.CommandType = CommandType.StoredProcedure
            wSqlCmd.CommandText = "Sexo_s"

            'Abro la conexión a la BD
            wSqlConn.Open()

            wSexList = New List(Of SexBE)
            wReader = wSqlCmd.ExecuteReader()
            While wReader.Read
                wSexBE = New SexBE

                wSexBE.Id = Convert.ToInt32(wReader("Id"))
                wSexBE.Description = Convert.ToString(wReader("Descripcion"))

                wSexList.Add(wSexBE)
            End While

            wSqlConn.Close()
        Catch ex As Exception
            Throw ex
        Finally
            wReader = Nothing
            wSqlCmd = Nothing
            wSqlConn = Nothing
        End Try

        Return wSexList
    End Function
#End Region

End Class
